package cn.edu.wfit.modules.learn.service.impl.coursemangement;

import java.util.List;
import cn.edu.wfit.common.core.utils.DateUtils;
import cn.edu.wfit.modules.learn.domain.WfitCourse;
import cn.edu.wfit.modules.learn.domain.WfitCourseVO;
import cn.edu.wfit.modules.learn.mapper.coursemangement.WfitCourseMapper;
import cn.edu.wfit.modules.learn.service.coursemangement.IWfitCourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 课程Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@Service
public class WfitCourseServiceImpl implements IWfitCourseService
{
    @Autowired
    private WfitCourseMapper wfitCourseMapper;

    /**
     * 查询课程
     * 
     * @param courseId 课程主键
     * @return 课程
     */
    @Override
    public WfitCourseVO selectWfitCourseByCourseId(Long courseId)
    {

        WfitCourse wfitCourse = wfitCourseMapper.selectWfitCourseByCourseId(courseId);
        WfitCourseVO wfitCourseVO = new WfitCourseVO();
        BeanUtils.copyProperties(wfitCourse, wfitCourseVO);
        Long countPeople=wfitCourseMapper.countWfitCourseByCourseId(courseId);
        countPeople = (countPeople != null) ? countPeople : 0;
        wfitCourseVO.setCountPeople(countPeople);

        return wfitCourseVO;
    }

    /**
     * 查询课程列表
     * 
     * @param wfitCourse 课程
     * @return 课程
     */
    @Override
    public List<WfitCourse> selectWfitCourseList(WfitCourse wfitCourse)
    {
        return wfitCourseMapper.selectWfitCourseList(wfitCourse);
    }

    /**
     * 新增课程
     * 
     * @param wfitCourse 课程
     * @return 结果
     */
    @Override
    public int insertWfitCourse(WfitCourse wfitCourse)
    {
        wfitCourse.setCreateTime(DateUtils.getNowDate());
        return wfitCourseMapper.insertWfitCourse(wfitCourse);
    }

    /**
     * 修改课程
     * 
     * @param wfitCourse 课程
     * @return 结果
     */
    @Override
    public int updateWfitCourse(WfitCourse wfitCourse)
    {
        wfitCourse.setUpdateTime(DateUtils.getNowDate());
        return wfitCourseMapper.updateWfitCourse(wfitCourse);
    }

    /**
     * 批量删除课程
     * 
     * @param courseIds 需要删除的课程主键
     * @return 结果
     */
    @Override
    public int deleteWfitCourseByCourseIds(Long[] courseIds)
    {
        return wfitCourseMapper.deleteWfitCourseByCourseIds(courseIds);
    }

    /**
     * 删除课程信息
     * 
     * @param courseId 课程主键
     * @return 结果
     */
    @Override
    public int deleteWfitCourseByCourseId(Long courseId)
    {
        return wfitCourseMapper.deleteWfitCourseByCourseId(courseId);
    }

    /**
     * 根据登录id查询课程列表
     * @param studentId
     * @return
     */
    @Override
    public List<WfitCourse> selectListById(String studentId) {
        return wfitCourseMapper.selectListById(studentId);
    }
}
